﻿Public Class Form1
    Private lds As dsSample

    Private Sub chkReadOnly_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkReadOnly.CheckedChanged
        comboSoS_ComboBox_Ext.ReadOnly = chkReadOnly.Checked
    End Sub

    Private Sub chkDisabled_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkDisabled.CheckedChanged
        comboSoS_ComboBox_Ext.ReadOnly = chkDisabled.Checked
    End Sub

    Private Sub btnGetData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetData.Click
        lds = New dsSample
        For ictr As Int16 = 0 To 50
            Dim dr As dsSample.MainTableRow = lds.MainTable.NewRow
            dr.Code = ictr
            dr.Description = "Description " & ictr.ToString
            If ictr Mod 2 Then
                dr.Rate = 1
            ElseIf ictr Mod 3 Then
                dr.Rate = 3
            Else
                dr.Rate = ictr
            End If
            If ictr = 3 Then
                dr.Rate = ""
            End If
            lds.MainTable.Rows.Add(dr)
        Next
        DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
        DataGridView1.DataSource = lds.MainTable

        For ictr As Int16 = 1 To 10
            Dim dr As dsSample.RatesRow = lds.Rates.NewRow
            dr.Rate = ictr
            dr.Description = "Desc " & ictr
            lds.Rates.Rows.Add(dr)
        Next
        comboSoS_ComboBox_Ext.SOS_DataBindings(lds.Rates, "Description", "Rate", lds.MainTable, "Rate", False)

        Dim ldr As dsSample.FilterRow
        ldr = lds.Filter.NewRow
        ldr.Size = 5
        ldr.Description = "<= 5"
        lds.Filter.Rows.Add(ldr)

        ldr = lds.Filter.NewRow
        ldr.Size = 5
        ldr.Description = ">= 6"
        lds.Filter.Rows.Add(ldr)

        comFilter.DataSource = lds.Filter
        comFilter.DisplayMember = "Description"
        comFilter.ValueMember = "Size"

        ComboBox1.DataSource = lds.Rates
        ComboBox1.DisplayMember = "Description"
        ComboBox1.ValueMember = "Rate"

        ComboBox1.DataBindings.Add(New Binding("SelectedValue", lds.MainTable, "Rate"))
        'comboSoS_ComboBox_Ext.Debug = True
    End Sub

    Private Sub comFilter_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comFilter.SelectedIndexChanged
        Try
            lds.Rates.DefaultView.RowFilter = "Rate " & comFilter.Text
            comboSoS_ComboBox_Ext.ApplyFilter()
        Catch ex As Exception

        End Try

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        comboSoS_ComboBox_Ext.SelectedValue = TextBox1.Text
    End Sub

    Private Sub comboSoS_ComboBox_Ext_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comboSoS_ComboBox_Ext.SelectedIndexChanged
        lblIndex.Text = comboSoS_ComboBox_Ext.SelectedIndex
    End Sub
End Class
